package com.ssl.sslliving.commodity.web;

import com.ssl.sslliving.commodity.entity.CategoryEntity;
import com.ssl.sslliving.commodity.service.CategoryService;
import com.ssl.sslliving.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @GetMapping(value = {"/", "/index.html"})
    private String indexPage(Model model) {
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categories();
        model.addAttribute("categories", categoryEntities);
        return "index";
    }

    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatalogJson() {
        Map<String,List<Catalog2Vo>> catalogJson = categoryService.getCatalogJson();
        return catalogJson;
    }

}
